package com.caibq.controller;

import com.atguigu.yygh.model.emp.Emp;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.caibq.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StopWatch;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * projectName: demoBox
 *
 * @author: caicai
 * time: 2024/1/3 12:34 周三
 * description:
 */
@RestController
@RequestMapping("/test")
public class TestController {

    @Autowired
    private BaseMapper baseMapper;
    /**
     * 分批次导出
     */
    @GetMapping("/NonThreadedCollection")
    public void NonThreadedCollection(){

        LambdaQueryWrapper<Emp> le = new LambdaQueryWrapper<Emp>().lt(Emp::getEmpno, 150000);
        List<Emp> dataList =baseMapper.selectList(le);

        // 非线程安全集合了
        List<Emp> successList = new ArrayList();
        List<Emp> failList = new ArrayList();

            // parallelStream 并行流中使用了不安全的集合 使用会出问题而stream没发现问题
        dataList.stream().forEach(
                vo -> {
                    if(vo.getEmpno()<120000) {
                        successList.add(vo);
                    } else {
                        failList.add(vo);
                    }
                }
        );
    }


}
